package body Communautes.implementation is

   --creer
   function creer return communaute is
   begin
      return (communautes.communaute with content => creer);
   end creer;

   ---inscrire
   function inscrire (x : communaute; n : individu) return communaute is
       pragma assert ( not est_inscrit (x, n));
   begin
      return (communautes.communaute with content => inscrire(x.content, n));
   end inscrire;

   ---est_inscrit
   function est_inscrit (x : communaute; n : individu) return boolean is
   begin
      return est_inscrit (x.content, n);
   end est_inscrit;

   ---nombre_inscrits
   function nombre_inscrits (x : communaute) return natural is
   begin
      return nombre_inscrits (x.content);
   end nombre_inscrits;

   ---ieme_inscrit---
   ------------------
   function ieme_inscrit (x : communaute; i : natural) return individu is
      pragma assert (1 <= i and i <= nombre_inscrits(x));
   begin
      return ieme_inscrit (x.content, i);
   end ieme_inscrit;

   --bloquer -----------
   ---------------------
   function bloquer (x : communaute; m : individu; n : individu) return communaute is
     pragma assert ( est_inscrit (x, m) and est_inscrit (x, n)
  			 and not est_bloque (x, m, n)
   			and not (m <= n and n <= m));
   begin
      return (communautes.communaute with content => (bloquer(x.content, m, n)));
   end bloquer ;

   --debloquer
  function debloquer (x : communaute; m : individu; n : individu) return communaute is
      pragma assert ( est_inscrit (x, m) and est_inscrit (x, n) and est_bloque (x, m, n)) ;
   begin
      return (communautes.communaute with content => (debloquer(x.content, m, n)));
   end debloquer;

   --est_bloque
   function est_bloque (x : communaute; m : individu; n : individu) return boolean is
   begin
      return est_bloque(x.content, m, n);
   end est_bloque ;

   ---est_cercle_de--
   ------------------
   function est_cercle_de (x : communaute; n : individu; c : cercle) return boolean is
   begin
      return est_cercle_de(x.content, n, c);
   end est_cercle_de;

   ---ajouter_cercle--
   ------------------
   function ajouter_cercle (x : communaute; n : individu; c : cercle) return communaute is
      pragma assert (est_inscrit (x, n) and not est_cercle_de(x, n, c)) ;
   begin
      return (communautes.communaute with content => (ajouter_cercle(x.content, n, c)));
   end ajouter_cercle;

 ---retirer_cercle--
   ------------------
   function retirer_cercle (x : communaute; n : individu; c : cercle) return communaute is
      pragma assert (est_inscrit (x, n) and est_cercle_de (x, n, c));
   begin
      return (communautes.communaute with content => (retirer_cercle(x.content, n, c)));
   end retirer_cercle;

   ---nombre_cercles_de--
   ------------------
   function nombre_cercles_de (x : communaute; n : individu) return natural is
   begin
      return nombre_cercles_de(x.content, n);
   end nombre_cercles_de ;

    ---ieme_cercle--
   ------------------
   function ieme_cercle (x : communaute; n : individu; i : natural) return cercle is
      pragma assert (est_inscrit(x, n) and 1 <= i and i <= nombre_cercles_de(x, n));
   begin
      return ieme_cercle(x.content, n, i);
   end ieme_cercle;

    ---est_membre_de--
   ------------------

   function est_membre_de (x : communaute; m : individu; c : cercle; n : individu) return boolean is
   begin
       return est_membre_de(x.content, m, c, n);
   end est_membre_de;

   ---ajouter_membre--
   ------------------
   function ajouter_membre (x : communaute; n : individu; c : cercle; p : individu) return communaute is
      pragma assert (est_inscrit (x, n) and est_inscrit (x, p)
                    and est_cercle_de (x, n, c) and not est_membre_de (x, n, c, p) and not (n <= p and p <= n));
   begin
      return (communautes.communaute with content=>(ajouter_membre(x.content, n, c, p)));
   end ajouter_membre;

   ---retirer_membre--
   ------------------
   function retirer_membre (x : communaute; n : individu; c : cercle; p : individu) return communaute is
    pragma assert ( est_inscrit (x, n) and est_inscrit (x, p) and
   			est_cercle_de (x, n, c) and est_membre_de (x, n, c, p));
   begin
      return (communautes.communaute with content=>(retirer_membre(x.content, n, c, p)));
   end retirer_membre ;

   ---nombre_membres_de--
   ------------------
   function nombre_membres_de (x : communaute; n : individu; c : cercle) return natural is
      pragma assert (est_inscrit(x, n));
   begin
      return nombre_membres_de(x.content, n, c);
   end  nombre_membres_de;

   ---ieme_membre--
   ------------------
   function ieme_membre (x : communaute; n : individu; c : cercle; i : natural) return individu is
      pragma assert (est_inscrit(x, n) and est_cercle_de(x, n, c) and 1 <= i and i <= nombre_membres_de(x, n, c));
   begin
      return ieme_membre (x.content, n, c, i);
      end ieme_membre;

   ------poster--------
   --------------------
   function poster(x : communaute; n : individu; c : cercle; t : texte) return communaute is
  	pragma assert (est_inscrit (x, n) and est_cercle_de(x, n, c));
   begin
       return (communautes.communaute with content => poster(x.content, n, c, t));
   end poster;

   ------commenter-----
   --------------------
   function commenter(x : communaute; n : individu; i : natural; t : texte) return communaute is
      pragma assert (est_inscrit(x ,n) and est_defini(consulter(x, n), i));
   begin
      return (communautes.communaute with content => commenter(x.content, n , i, t));
   end commenter;

   ------nombre_posts-----
   -----------------------
   function nombre_posts(x : communaute) return natural is
   begin
      return nombre_posts(x.content);
   end nombre_posts;

   --------consulter---------
   --------------------------
   function consulter(x : communaute; n : individu) return mur is
      	pragma assert (est_inscrit(x,n));
   begin
      return consulter(x.content,n);
   end consulter;

end Communautes.implementation;

